
const Game = require("../Game");

cc.Class({
    extends: cc.Component,

    properties: {
        // 聊天区
        panelChat: cc.Node,
        // 玩家详情
        panelSocial: cc.Node,
        // 下注状态
        betStateUI: cc.Node,
        // 游戏状态
        gameStateUI: cc.Node,
        resultTxt: cc.Label,
        // 倒计时
        betCounter: cc.ProgressBar,
        btnStart: cc.Node,
        // 金币总数
        labelTotalChips: cc.Label,

    },

    init: function(betDuration) {
        this.panelChat.active = false;
        this.panelSocial.active = false;
        this.resultTxt.enabled = false;
        this.betStateUI.active = false;
        this.gameStateUI.active = false;
        this.btnStart.active = false;
        // 倒计时
        this.betDuration = betDuration;
        this.betTimer = 0;
        // 是否倒计时中
        this.isBetCounting = false;
    },

    startCountDown: function() {
        if (this.betCounter) {
            this.betTimer = 0;
            this.isBetCounting = true;
        }
    },

    resetCountDown: function () {
        if (this.betCounter) {
            this.betTimer = 0;
            this.isBetCounting = false;
            this.betCounter.progress = 0;
        }
    },

    showBetState: function () {
        this.betStateUI.active = true;
        this.gameStateUI.active = false;
        this.btnStart.active = false;
    },

    showGameState: function () {
        this.betStateUI.active = false;
        this.gameStateUI.active = true;
        this.btnStart.active = false;
    },

    showResultState: function () {
        this.betStateUI.active = false;
        this.gameStateUI.active = false;
        this.btnStart.active = true;
    },

    // 开启/隐藏聊天
    toggleChat: function () {
        // 机智
        this.panelChat.active = !this.panelChat.active;
    },

    toggleSocial: function () {
        this.panelSocial.active = !this.panelSocial.active;
    },

    // 更新定时器外面的圆圈
    update: function (dt) {
        if (!this.isBetCounting) {
            return;
        }
        this.betCounter.progress = this.betTimer/this.betDuration;
        this.betTimer += dt;
        if (this.betTimer >= this.betDuration) {
            this.isBetCounting = false;
            this.betCounter.progress = 1;
        }
    }
});
